# pickle模块
import pickle

# dump和load
# dump  传入数据和文件对象
d = {'a': '1', 'b': '2'}

d_pickle = pickle.dumps(d)
print(d_pickle)  # pickle序列化后是二进制
# b'\x80\x04\x95\x15\x00\x00\x00\x00\x00\x00\x00}\x94(\x8c\x01a\x94\x8c\x011\x94\x8c\x01b\x94\x8c\x012\x94u.'

with open('a.pickle', 'wb') as f:
    pickle.dump(d, f)

# load  传入文件对象
with open('a.pickle', 'rb') as f:
    res = pickle.load(f)
    print(res, type(res))  # {'a': '1', 'b': '2'} <class 'dict'>

# import pickle
# import time
#
# t = time.localtime(1000000000)
# # dump  传入数据和文件对象
#
#
# with open('a.pickle', 'wb') as f:
#     pickle.dump(t, f)
#
# # load  传入文件对象
# with open('a.pickle', 'rb') as f:
#     res = pickle.load(f)
#     print(res, type(
#         res))  # time.struct_time(tm_year=2001, tm_mon=9, tm_mday=9, tm_hour=9, tm_min=46, tm_sec=40, tm_wday=6, tm_yday=252, tm_isdst=0) <class 'time.struct_time'>
